var buttonPN = function (btn, evt) {
    //Setting up the button ui...

    var bitwise = 0;
    var temp = ROSpanel.btnCount;
    var ROSitems = ROSpanel.dockedItems[0].items;
    var ROSbadge = ROSitems.items[0];
    var ROSbNumber = parseInt(ROSpanel.btnCount);
        ROSnNumber = isNaN(ROSbNumber) ? 0 : ROSbNumber;


    var chgBadge = function(x, idx) {
        if (idx>1) {
            bitwise += temp%2;
            temp = Math.floor(temp/2);
        }
//        console.debug(ROSpanel.btnCount+':'+temp+':'+bitwise);
    }

    var isThisAdd = function(x, idx) {
        // returns true if x is current item
        if (btn.id == ROSitems.items[idx].id) {
            ROSnNumber += Math.pow(2,idx-2);
            ROSpanel.btnCount = ROSnNumber;
//            console.debug(ROSpanel.btnCount+':'+temp+':'+bitwise);
//            ToolbarDemo.views.Patientdetail.update;
        }
    }

    var isThisSub = function(x, idx) {
        // returns true if x is current item
        if (btn.id == ROSitems.items[idx].id) {
            ROSnNumber -= Math.pow(2,idx-2);
            temp -= Math.pow(2,idx-2);
            ROSpanel.btnCount = ROSnNumber;
//            console.debug(ROSpanel.btnCount+':'+temp+':'+bitwise);
            ROSitems.items[0].update;
//            ToolbarDemo.views.Patientdetail.update;
        }
    }

    if(btn.ui == 'normal'){
        btn.ui = 'confirm';
        btn.el.removeCls('x-button-normal');
        btn.el.addCls('x-button-confirm');
        ROSitems.items.forEach(isThisAdd);
        temp = ROSpanel.btnCount;
        ROSitems.items.forEach(chgBadge);
        Ext.getCmp('const').setBadge(bitwise);
//        Ext.getCmp('const1').setBadge(bitwise);
//        Ext.getCmp('const2').setBadge(bitwise);
//        console.debug(bitwise);
//        console.debug(this.id);
//        ROSbadge.Button.setBadge(this.getId());
//        console.log(ToolbarDemo.ROSpanel.items.items.indexOf(this.id));  //.tab.badgeText = '1';
    } else {
        if (btn.ui == 'confirm'){
        btn.ui = 'decline';                                
        btn.el.removeCls('x-button-confirm');
        btn.el.addCls('x-button-decline');
        } else {
            btn.ui = 'normal';
            btn.el.removeCls('x-button-decline');
            btn.el.addCls('x-button-normal');
            ROSitems.items.forEach(isThisSub);
            temp = ROSpanel.btnCount;
            ROSitems.items.forEach(chgBadge);
  // KR          console.debug(bitwise);
            Ext.getCmp('const').setBadge(bitwise);
  //          Ext.getCmp('const1').setBadge(bitwise);
  //          Ext.getCmp('const2').setBadge(bitwise);
        }
    }                        
};

var ROSpanel = {
    centered: false,
    btnCount: 0,
//   html: 'Test1',
//   id: ROSpanel,
//    initComponent: function() {
//        Ext.apply(this, {
    dockedItems: [{
        xtype: 'toolbar',
        dock: 'top',
        scroll: {
            direction: 'horizontal',
            useIndicators: false
        },
	    items: [
	        {
	            xtype: 'button',
	            text: 'CONSTITUTION',
	            id: 'const',
	            disabled: false,
	            ui: 'action'
	        }, {
	            xtype: 'spacer'
	        }, {
	            xtype: 'button',
	            id: 'wgain',
	            text: 'Weight Gain',
	            width: 120,
	            handler:  buttonPN
	        }, {
	            xtype: 'button',
	            id: 'wloss',
	            text: 'Weight Loss',
	            width: 120,
	            handler:  buttonPN
	        }, {
	            xtype: 'button',
	            id: 'anorxia',
	            name: 'anorxia',
	            text: 'Anorexia',
	            width: 120,
	            handler:  buttonPN
	        }, {
	            xtype: 'button',
	            id: 'fever',
	            name: 'fever',
	            text: 'Fever',
	            width: 120,
	            handler:  buttonPN
	        }, {
	            xtype: 'button',
	            id: 'chills',
	            name: 'chills',
	            text: 'Chills',
	            width: 120,
	            handler:  buttonPN
	        }, {
	            xtype: 'button',
	            id: 'nsweats',
	            name: 'nsweats',
	            text: 'Night Sweats',
	            width: 120,
	            handler:  buttonPN
	        }, {
	            xtype: 'button',
	            id: 'fatigue',
	            name: 'fatigue',
	            text: 'Fatigue',
	            width: 120,
	            handler:  buttonPN
	        }, {
	            xtype: 'button',
	            id: 'weakness',
	            name: 'weakness',
	            text: 'Weakness',
	            width: 120,
	            handler:  buttonPN
	        }, {
	            xtype: 'button',
	            id: 'insomnia',
	            name: 'insomnia',
	            text: 'Insomnia',
	            width: 120,
	            handler:  buttonPN
	        }, {
	            xtype: 'button',
	            id: 'pain',
	            name: 'pain',
	            text: 'Pain',
	            width: 120,
	            handler:  buttonPN
	        }]
	    }]
//        });
//        demos.ROSpanel.superclass.initComponent.apply(this, arguments)
//    }
};
